DECLARE SUB CenterText ()
DECLARE SUB DissolveScreen ()
DECLARE SUB Dead ()
DECLARE SUB Backspace ()
DECLARE SUB PressAnyKey ()
'$INCLUDE: 'c:\bc7\programs\theta\global.bi'

SUB Backspace
      row = CSRLIN
      column = POS(0)
      J% = LEN(Passwrd) - 1
      Passwrd = LEFT$(Passwrd, J%)
      column = column - 1
      LOCATE row, column
      PRINT " ";
      LOCATE CSRLIN, column
END SUB

SUB CannotGo

  COLOR 15, 0, 9
  PRINT "You cannot go that direction."
  COLOR 7, 0, 8

END SUB

SUB CenterText

  LOCATE CSRLIN, 40 - INT(LEN(Text) / 2)
  PRINT Text


END SUB

SUB Dead

  COLOR 9, 0, 9
  PRINT
  PRINT "The End."
  COLOR 7, 0, 8
  PressAnyKey
  END


END SUB

SUB DissolveScreen
    DIM ScreenPos%(2000)
    FOR X% = 1 TO 2000
        ScreenPos%(X%) = X%
    NEXT X%

    FOR X% = 1 TO 2000
        SWAP ScreenPos%(X%), ScreenPos%(INT(RND(1) * 2000) + 1)
    NEXT X%

    FOR X% = 1 TO 2000
        R% = ScreenPos%(X%) \ 80 + 1
        IF R% = 0 THEN R% = 1
        IF R% > 25 THEN R% = 25
        C% = ABS(ScreenPos%(X%) - (80 * R%))
        IF C% = 0 THEN C% = 1
        LOCATE R%, C%
        PRINT " ";
    NEXT X%

    LOCATE 1, 80: PRINT " ";   ' cheap temporary fix
END SUB

SUB Help

  CLS
  LOCATE , , 0
  LOCATE 2, 3: COLOR 11, 0, 9: PRINT "GENERAL COMMANDS:"
  LOCATE 4, 3: COLOR 15, 0, 8: PRINT "N"
  LOCATE 4, 5: COLOR 7, 0, 8: PRINT "- go north"
  LOCATE 5, 3: COLOR 15, 0, 8: PRINT "S"
  LOCATE 5, 5: COLOR 7, 0, 8: PRINT "- go south"
  LOCATE 6, 3: COLOR 15, 0, 8: PRINT "E"
  LOCATE 6, 5: COLOR 7, 0, 8: PRINT "- go east"
  LOCATE 7, 3: COLOR 15, 0, 8: PRINT "W"
  LOCATE 7, 5: COLOR 7, 0, 8: PRINT "- go west"
  LOCATE 8, 3: COLOR 15, 0, 8: PRINT "SEARCH"
  LOCATE 8, 10: COLOR 7, 0, 8: PRINT "- search the room"
  LOCATE 9, 3: COLOR 15, 0, 8: PRINT "USE <item>"
  LOCATE 9, 14: COLOR 7, 0, 8: PRINT "- use an item"
  LOCATE 10, 3: COLOR 15, 0, 8: PRINT "I"
  LOCATE 10, 5: COLOR 7, 0, 8: PRINT "- inspect your inventory"
  LOCATE 11, 3: COLOR 15, 0, 8: PRINT "OBJ"
  LOCATE 11, 9: COLOR 7, 0, 8: PRINT "- inspect mission objectives"
  LOCATE 12, 3: COLOR 15, 0, 8: PRINT "LOOK"
  LOCATE 12, 8: COLOR 7, 0, 8: PRINT "- reprint room description"
  LOCATE 13, 3: COLOR 15, 0, 8: PRINT "HELP"
  LOCATE 13, 8: COLOR 7, 0, 8: PRINT "- display this screen"
  LOCATE 14, 3: COLOR 15, 0, 8: PRINT "QUIT"
  LOCATE 14, 8: COLOR 7, 0, 8: PRINT "- quit the game"

BottomColumn:
  Text = "Discover other commands for yourself - you'll need them."
  CenterText
  PressAnyKey

END SUB

SUB Inventory

  COLOR 15, 0, 9
  PRINT "Inventory:"
  COLOR 7, 0, 8
  IF virus = 1 THEN PRINT "  1123-theta Virus"
  IF cyberjack = 1 THEN PRINT "  Cyberjack"
  IF keyalpha = 1 THEN PRINT "  Keycard Alpha"
  IF keybeta = 1 THEN PRINT "  Keycard Beta"
  IF powercrystal = 1 THEN PRINT "  Power Crystal"
  IF powerjack = 1 THEN PRINT "  Power Jack"
  IF suit = 1 OR suit = 2 THEN PRINT "  Pressure Suit"
  IF disc = 1 THEN PRINT "  Software Disc"

END SUB

SUB Objectives

  COLOR 15, 0, 9
  PRINT "Mission Objectives:"
  COLOR 7, 0, 8
  IF power = 0 THEN COLOR 12, 0, 9: PRINT "  INCOMPLETE";
  IF power = 1 THEN COLOR 9, 0, 9: PRINT "  SUCCESSFUL";
  COLOR 7, 0, 8
  PRINT "  Restore power"
  IF cyberspacevirus = 0 THEN COLOR 12, 0, 9: PRINT "  INCOMPLETE";
  IF cyberspacevirus = 1 THEN COLOR 9, 0, 9: PRINT "  SUCCESSFUL";
  COLOR 7, 0, 8
  PRINT "  Infect cyberspace computer system"
  IF virus = 0 THEN COLOR 12, 0, 9: PRINT "  INCOMPLETE";
  IF virus = 1 THEN COLOR 9, 0, 9: PRINT "  SUCCESSFUL";
  COLOR 7, 0, 8
  PRINT "  Obtain 1123-theta virus"

END SUB

SUB Password

row = CSRLIN             '  line where input prompts start
column = 1               '  column where input prompts start
ColTemp% = column        '  backup of Column variable
Prompt2$ = "Password: "  '  password prompt
PassLen% = 15            '  max length of legal passwords
ValidPass$ = "TRUSTNO1"  '  secret valid user password

' Now get the user password
row = row + 1
column = ColTemp%
IF row = 26 THEN
        row = 25
        LOCATE 25, 80
        PRINT
END IF
LOCATE row, column
PRINT Prompt2$;
  column = ColTemp% + LEN(Prompt2$)
  LOCATE row, column
  PRINT SPACE$(79 - column);  'CLEARS AFTER PROMPT
REM PRINT SPACE$(79 - (Column + LEN(Prompt2$)));  'CLEARS AFTER PROMPT
  LOCATE row, column, 1
  Passwrd = ""
  DO
    DO
      UserKey$ = UCASE$(INKEY$)
    LOOP UNTIL LEN(UserKey$)     ' wait for a keypress
    UK% = ASC(UserKey$)
   
' backspace key pressed?
    IF (UK% = 8) AND (LEN(Passwrd) > 0) THEN
       Backspace
    END IF

' build users password
    IF (UK% > 32) AND (UK% < 127) THEN
       column = column + 1
       PRINT "*";
       Passwrd = Passwrd + UserKey$
    END IF
  LOOP UNTIL (UK% = 13) OR (LEN(Passwrd) > PassLen%)
  Secret = Passwrd

END SUB

SUB PressAnyKey
DO
  LOOP WHILE INKEY$ = ""
END SUB

SUB Quit
  COLOR 11, 0, 9: PRINT
  PRINT "Are you sure that you want to quit? ";
  LOCATE , , 1

QuitSub:
  Temp$ = ""
  DO
  Temp$ = INKEY$
  Temp$ = UCASE$(Temp$)
  LOOP UNTIL LEN(Temp$) > 0
  IF Temp$ = "N" THEN PRINT "no": GOTO NotQuit
  IF Temp$ = "Y" THEN PRINT "yes": GOTO YesQuit
  GOTO QuitSub

YesQuit:
  LOCATE , , 0
  COLOR 7, 0, 8
  PressAnyKey
  DissolveScreen
  END

NotQuit:
  COLOR 7, 0, 8
  PRINT
END SUB

SUB Teletype
    d! = 3

'   if no delay, assign default
    IF d! < 1 THEN
       d! = 5
    END IF

'   change delay to 100ths second
    d! = d! / 100

'   print text 1 char at a time, with a "click" after non-space characters

    FOR X% = 1 TO LEN(Text)

        T$ = MID$(Text, X%, 1)
        PRINT T$;
        IF T$ <> " " THEN
           SOUND 20000, 1
        END IF

'       get current value of TIMER
        CurrentTimer! = TIMER

'       delay appropriate time
        WHILE TIMER < (CurrentTimer! + d!)
        WEND

'       stop delaying if a key is pressed
        IF INKEY$ <> "" THEN
           d! = 0
        END IF

    NEXT X%

END SUB

